package org.feng.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.NonNull;
import org.feng.common.*;
import org.feng.entity.User;
import org.feng.sensitive.Base64Sensitive;

import java.time.LocalDateTime;

/**
 * 用户VO类
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2023年08月24日 23时23分
 */
@Data
@MaskedEntity
public class UserVO implements Response {
    /**
     * 用户名
     */
    @ExcelProperty(value = "用户名")
    private String username;

    /**
     * 年龄
     */
    @ExcelProperty(value = "年龄")
    private Integer age;

    /**
     * 邮箱
     */
    @ExcelProperty(value = "邮箱")
    @MaskedField(type = SensitiveDataTypeEnum.EMAIL)
    private String email;

    /**
     * 电话
     */
    @ExcelProperty(value = "电话")
    @MaskedField(type = SensitiveDataTypeEnum.PHONE, sensitiveType = Base64Sensitive.SENSITIVE_TYPE_CODE)
    private String phone;

    /**
     * 创建时间
     */
    @ExcelProperty(value = "创建时间", converter = LocalDateTimeConverter.class)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @ExcelProperty(value = "更新时间", converter = LocalDateTimeConverter.class)
    private LocalDateTime updateTime;

    public UserVO copyFieldByUser(@NonNull User user) {
        this.setUsername(user.getUsername());
        this.setAge(user.getAge());
        this.setPhone(user.getPhone());
        this.setEmail(user.getEmail());
        this.setCreateTime(user.getCreateTime());
        this.setUpdateTime(user.getUpdateTime());
        return this;
    }
}
